from typing import List


class Solution:
    def gameOfLife(self, board: List[List[int]]) -> None:
        chnageDict = {}
        for i in range(len(board)):
            for k in range(len(board[0])):
                num = self._count(board, i, k)
                if (num < 2 or num > 3) and board[i][k] == 1:
                    chnageDict[(i, k)] = 0
                elif num == 3 and board[i][k] == 0:
                    chnageDict[(i, k)] = 1

        for (i, k), v in chnageDict.items():
            board[i][k] = v

    def _count(self, board: List[List[int]], i: int, k: int) -> int:
        if 0 < i < len(board) - 1 and 0 < k < len(board[0]) - 1:
            return board[i - 1][k - 1] + board[i - 1][k] + board[i - 1][
                k + 1] + board[i][k - 1] + board[i][k + 1] + board[i + 1][
                    k - 1] + board[i + 1][k] + board[i + 1][k + 1]

        if len(board) == 1 and len(board[0]) == 1:
            return 0
        elif len(board) == 1:
            if k == 0:
                return board[0][1]
            elif k == len(board[0]) - 1:
                return board[0][k - 1]
            else:
                return board[0][k - 1] + board[0][k + 1]
        elif len(board[0]) == 1:
            if i == 0:
                return board[1][0]
            elif i == len(board) - 1:
                return board[i - 1][0]
            else:
                return board[i - 1][0] + board[i + 1][0]

        if i == 0:
            if k == 0:
                return board[0][1] + board[1][1] + board[1][0]
            elif k == len(board[0]) - 1:
                return board[0][k - 1] + board[1][k - 1] + board[1][k]
            else:
                return board[i][k - 1] + board[i][k + 1] + board[i + 1][
                    k - 1] + board[i + 1][k] + board[i + 1][k + 1]

        if i == len(board) - 1:
            if k == 0:
                return board[i - 1][0] + board[i - 1][1] + board[i][1]
            elif k == len(board[0]) - 1:
                return board[i - 1][k - 1] + board[i][k - 1] + board[i - 1][k]
            else:
                return board[i - 1][k - 1] + board[i - 1][k] + board[i - 1][
                    k + 1] + board[i][k - 1] + board[i][k + 1]

        if k == 0:
            return board[i - 1][0] + board[i - 1][1] + board[i][1] + board[
                i + 1][0] + board[i + 1][1]

        if k == len(board[0]) - 1:
            return board[i - 1][k - 1] + board[i - 1][k] + board[i][
                k - 1] + board[i + 1][k - 1] + board[i + 1][k]


# cells = [[0, 1, 0], [0, 0, 1], [1, 1, 1], [0, 0, 0]]
cells = [[1],[1],[0],[1],[0],[1]]
Solution().gameOfLife(cells)
print(cells)